package com.bw.zg3park2212.mem

import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.MemAddParam
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.databinding.ActivityMemBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path="/app/MemActivity")
class MemActivity : BaseActivity<ActivityMemBinding,MemViewModel>() {
    override fun intitView() {
        //SPUtils.getInstance().getInt("userid")
        if (SPUtils.getInstance().getString("mem").isNotEmpty()){
            binding.membershipLevel.text=SPUtils.getInstance().getString("mem")
            viewmodel.mem(1119)
        }
        binding.membershipLevel.setOnClickListener {
            binding.membershipLevel.text="黄金会员"
            if (binding.membershipLevel.text=="办理会员"){
                var memAddParam=MemAddParam()
                memAddParam.userId=SPUtils.getInstance().getInt("userid")
                memAddParam.username=SPUtils.getInstance().getString("username")
                viewmodel.memadd(memAddParam)
            }
        }
        viewmodel.mem(1119)
        binding.staute.setOnClickListener {it1->
            if (binding.rb1.isChecked){
                binding.rb2.isChecked=true
                viewmodel.memup(1119,"铂金会员")
            }else if(binding.rb2.isChecked){
                viewmodel.memup(1119,"钻石会员")
                binding.rb3.isChecked=true
                ToastUtils.showLong("已是最高等级")
            }
        }
        viewmodel.menber(59)
        binding.rb1.setOnClickListener {
            viewmodel.menber(58)
        }
        binding.rb2.setOnClickListener {
            viewmodel.menber(59)
        }
        binding.rb3.setOnClickListener {
            viewmodel.menber(60)
        }
    }

    override fun intitData() {
        viewmodel.memaddSuccse.observe(this){
            ToastUtils.showLong("办理成功")
            viewmodel.mem(1119)
        }
        viewmodel.memSuccse.observe(this){
                binding.membershipLevel.text=it.membershipLevel
                binding.registrationDate.text=it.registrationDate
            SPUtils.getInstance().getString("mem",it.membershipLevel)
            if (it.membershipLevel=="黄金会员"){
                binding.rb1.isChecked=true
            }else if(it.membershipLevel=="铂金会员"){
                binding.rb2.isChecked=true
            }else if(it.membershipLevel=="钻石会员"){
                binding.rb3.isChecked=true
            }
        }
        viewmodel.memupSuccse.observe(this){
            binding.membershipLevel.text=it.membershipLevel
            ToastUtils.showLong("升级成功")
        }
        viewmodel.menberSuccse.observe(this){
            binding.tv1.text="商家"+it.merchantDiscount+"折"
            binding.tv2.text=""+it.pointsToCash+"积分抵1元"
            binding.tv3.text=""+it.parkingCoupons+"元停车券"
        }
    }

}